package com.tonann.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.extra.qrcode.QrCodeUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tonann.common.annotation.Log;
import com.tonann.common.core.controller.BaseController;
import com.tonann.common.core.domain.AjaxResult;
import com.tonann.common.enums.BusinessType;
import com.tonann.app.domain.AppDeviceModel;
import com.tonann.app.service.IAppDeviceModelService;
import com.tonann.common.utils.poi.ExcelUtil;
import com.tonann.common.core.page.TableDataInfo;

/**
 * 设备型号管理Controller
 * 
 * @author tonann
 * @date 2023-07-31
 */
@RestController
@RequestMapping("/app/deviceModel")
public class AppDeviceModelController extends BaseController
{
    @Autowired
    private IAppDeviceModelService appDeviceModelService;

    /**
     * 查询设备型号管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:deviceModel:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppDeviceModel appDeviceModel)
    {
        startPage();
        List<AppDeviceModel> list = appDeviceModelService.selectAppDeviceModelList(appDeviceModel);
        return getDataTable(list);
    }

    /**
     * 导出设备型号管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:deviceModel:export')")
    @Log(title = "设备型号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppDeviceModel appDeviceModel)
    {
        List<AppDeviceModel> list = appDeviceModelService.selectAppDeviceModelList(appDeviceModel);
        ExcelUtil<AppDeviceModel> util = new ExcelUtil<AppDeviceModel>(AppDeviceModel.class);
        util.exportExcel(response, list, "设备型号管理数据");
    }

    /**
     * 获取设备型号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:deviceModel:query')")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        return AjaxResult.success(appDeviceModelService.selectAppDeviceModelByModelId(modelId));
    }

    /**
     * 新增设备型号管理
     */
    @PreAuthorize("@ss.hasPermi('app:deviceModel:add')")
    @Log(title = "设备型号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppDeviceModel appDeviceModel) throws Exception
    {
        int flag = appDeviceModelService.insertAppDeviceModel(appDeviceModel);
        if (flag == 0){
            return  AjaxResult.error("设备型号编号重复");
        }else {
            return  toAjax(1);
        }
    }

    /**
     * 修改设备型号管理
     */
    @PreAuthorize("@ss.hasPermi('app:deviceModel:edit')")
    @Log(title = "设备型号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppDeviceModel appDeviceModel) throws Exception
    {
        int flag = appDeviceModelService.updateAppDeviceModel(appDeviceModel);
        if (flag == 0){
            return  AjaxResult.error("设备型号编号重复");
        }else {
            return  toAjax(1);
        }
    }

    /**
     * 删除设备型号管理
     */
    @PreAuthorize("@ss.hasPermi('app:deviceModel:remove')")
    @Log(title = "设备型号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable Long[] modelIds)
    {
        return toAjax(appDeviceModelService.deleteAppDeviceModelByModelIds(modelIds));
    }
}
